import { ArchiveDeptids } from './archiveDeptid';
let _ArchiveDeptids = ArchiveDeptids;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import ArchiveDeptidMock from './mdp/arc/archiveDeptidMock';
 * ArchiveDeptidMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/archiveDeptid/listKey').reply(config => {
      let params = config.params;
      let mockArchiveDeptids = _ArchiveDeptids.filter(archiveDeptid => {
      	if(params.id||params.id==''){ if( archiveDeptid.id.indexOf(params.id)>=0) return true;}
      	if(params.archiveId||params.archiveId==''){ if( archiveDeptid.archiveId.indexOf(params.archiveId)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( archiveDeptid.deptid.indexOf(params.deptid)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockArchiveDeptids
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/archiveDeptid/list').reply(config => {
      let params = config.params;
      let mockArchiveDeptids = _ArchiveDeptids.filter(archiveDeptid => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(archiveDeptid.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.archiveId||params.archiveId==''){if(archiveDeptid.archiveId.indexOf(params.archiveId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(archiveDeptid.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockArchiveDeptids
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockArchiveDeptids.length;
      mockArchiveDeptids = mockArchiveDeptids.filter((archiveDeptid, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockArchiveDeptids,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/archiveDeptid/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _ArchiveDeptids = _ArchiveDeptids.filter(archiveDeptid => archiveDeptid.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/archiveDeptid/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _ArchiveDeptids = _ArchiveDeptids.filter(archiveDeptid => !params.includes(archiveDeptid.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/archiveDeptid/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,deptid } = params;
      _ArchiveDeptids.some(archiveDeptid => {
        if (archiveDeptid.id === id) {
			archiveDeptid.id = id;
			archiveDeptid.archiveId = archiveId;
			archiveDeptid.deptid = deptid
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/archiveDeptid/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,archiveId,deptid } = params;
      _ArchiveDeptids.push({
		id:id,
		archiveId:archiveId,
		deptid:deptid
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};